package com.alittle.module.login;

import com.alittle.mvp.mine.ILoginPresenter;
import com.alittle.mvp.mine.ILoginView;
import com.alittle.support.support.mvp.MvpBasePresenter;

/**
 * Created by wom on 2015/8/18.
 */
public class LoginPresenter extends MvpBasePresenter<ILoginView> implements ILoginPresenter {

    private final static int PHONE_NUMBER_DIGIT = 11;
    private final static int VERIFY_CODE_DIGIT = 6;

    public final static int TYPE_PHONE = 0;
    public final static int TYPE_VERIFY_CODE = 1;


    @Override
    public void verifyInvaild(int type, String content) {

        if (type == TYPE_PHONE) {

            if (isPhoneAvailable(content)) {
                getView().showPhoneLegal();
            } else {
                getView().showPhoneIllegal();
            }

        } else if (type == TYPE_VERIFY_CODE) {

            if (isVerifyCodeAvailable(content)) {
                getView().enableLogin();
            } else {
                getView().disableLogin();
            }
        } else {
            getView().showPhoneIllegal();
            getView().disableLogin();
        }
    }

    @Override
    public void requestVerifyCode(String phoneNumber) {
        //Todo 请求验证码
    }

    @Override
    public void login(String phoneNumber, String verifyCode) {
        //TODO 请求登陆
        getView().showLogging();
        getView().showLoginSuccess(phoneNumber);

    }

    //////////////////////////////////////PRIVATE//////////////////////////////////////////////////

    private static boolean isPhoneAvailable(String phone) {
        return phone.length() == PHONE_NUMBER_DIGIT;
    }

    private static boolean isVerifyCodeAvailable(String verifyCode) {
        return verifyCode.length() == VERIFY_CODE_DIGIT;
    }
}
